import React, { Component } from 'react'
import { CounterContext } from './Context'

// #3 使用 CounterContext.Consumer 配合函数消费数据
export default class Child2 extends Component {
  render() {
    return (
      <CounterContext.Consumer>
        {({ count, changeCount }) => (
          <div>
            <p>Child2: {count}</p>
            <button onClick={() => changeCount(2)}>+2</button>
          </div>
        )}
      </CounterContext.Consumer>
    )
  }
}
